import request from '@/common/request';
import requestPlat from '@/common/requestPlat';
import util from '@/common/util';
import config from '@/config/env'
import md5 from 'js-md5';
import Qs from 'qs';

// 获取验证码
export let getCode = (params) => {
	return requestPlat({
		method: 'get',
		url: 'common/data/get_sms_code',
		params
	})
}

//图片上传
export let imgUpload= (file) => {
	return new Promise(resolve => {
		let url = config[config.mchType].baseUrl + 'file/data/upload'
		var timestamp = new Date().getTime();
		var signToken = util.getLocalCache('token');
		uni.uploadFile({
			url, 
			filePath: file,
			name: 'file',
			header:{
				"platid":config.platid,
				"type": config.type,
				"authority": 0,
				"timestamp": timestamp,
				"authorization": signToken,
				"sign": md5(timestamp + signToken + "open@2023@vdigit"),
				// "Content-Type": 'multipart/form-data'
			},
			success: res => {
				resolve(res)
			},
			fail: err => {
				console.log(err)
			}
		})
	})
}

// 获取小程序OpenId接口  参数  code 授权码
export let getOpenId = (params) => {
	return request({
		url: `common/data/get_openid_session`,
		method: 'get',
		params
	})
}

// h5获取微信openid  参数  code 授权码
export let getVisitOpenId = (params) => {
	return request({
		url: `common/data/get_visit_info`,
		method: 'get',
		params
	})
}

// h5分享 参数  url 分享链接
export let getShareInfo = (params) => {
	return request({
		url: `common/data/get_share_info`,
		method: 'get',
		params
	})
}


// 获取位置
export let getLocation = (params) => {
	return requestPlat({
		method: 'get',
		url: 'map/data/location/get',
		params
	})
}
// 枚举
export let myEnum = (params) => {
	return request({
		method: 'get',
		url: 'user/data/util/enum/list',
		params
	})
}
// 商户详情
export let getMerchant = (params) => {
	return request({
		method: 'get',
		url: 'merchant/data/detail',
		params
	})
}

// 字典
export let listDict = (params) => {
	return request({
		method: 'get',
		url: 'system/data/util/dict/values',
		params
	})
}

// 获取企业使用协议
export let listProtocol = (params) => {
	return request({
		method: 'get',
		url: 'system/data/protocol/list',
		params
	})
}


// 获取平台详情
export let getPlatDetail = (params) => {
	return request({
		method: 'get',
		url: 'merchant/data/plat/detail',
		params
	})
}


export let getConfig = (params) => {
	return request({
		method: 'get',
		url: 'merchant/data/config/detail',
		params
	})
}
export let procureEnum = (params) => {
	return requestPlat({
		method: 'get',
		url: 'procure/data/util/enum/list',
		params
	})
}





